/*
 * This file is part of animus, a GUI for the command line app "GHost++"
 *
 * http://code.google.com/p/animus/
 *
 * Copyright (C) 2008-2009 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

/*
 * This file is part of animus, a GUI for the command line app "GHost++"
 *
 * Copyright (C) 2008-2009 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.ComponentModel;

namespace animus
{
    public class ConsoleTriggerSendKeys : ConsoleTrigger
    {
        public ConsoleTriggerSendKeys()
        {
            
        }

        protected override void Triggered(string line, System.Text.RegularExpressions.Match match)
        {
            IntPtr wc3 = Win32.FindWindow("Warcraft III", "Warcraft III");
            if (wc3 == IntPtr.Zero)
                throw new Exception("Could not find Warcraft III window");
            string msgText = match.Result(m_Message);
            if (msgText == string.Empty)
                throw new Exception("Text to send to Warcraft III window is empty!");
            IntPtr foreGroundWindow = Win32.GetForegroundWindow();
            Win32.SetForegroundWindow(wc3);
            SendKeys.Send("{ENTER}" + msgText + "{ENTER}");
            Win32.SetForegroundWindow(foreGroundWindow);
        }
        protected string m_Message;
        [Category("Text output")]
        [Description("The text that will be sent as chat to Warcraft III")]
        public string Message
        {
            get { return m_Message; }
            set { m_Message = value; }
        }
        public override string GetDescription()
        {
            return "Automatically send chat text in Warcraft III";
        }
        public override string GetParameters()
        {
            return "Send chat: '" + m_Message + "'";
        }
    }
}
